<template>
  <Dialog v-model="dialogVisible" :appendToBody="true" title="邀请记录" width="70%">
    <!-- 搜索工作栏 -->

    <!-- 列表 -->
    <el-table v-loading="loading" :data="list" show-overflow-tooltip>
      <el-table-column label="主键id" align="center" prop="id" v-if="false"/>

      <el-table-column label="用户id" align="center" prop="id" />
      <el-table-column label="用户昵称" align="center" prop="nickname" />
      <el-table-column align="center" label="状态" prop="status" width="100px">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.WITHDRAW_STATUS" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="提现金额" align="center" prop="withdraw" />
      <el-table-column label="具体账号" align="center" prop="aliAccount" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column align="center" label="付款截图" prop="screenshotUrl" width="80px">
        <template #default="scope">
          <img :src="scope.row.screenshotUrl" style="width: 40px" />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="150px">
        <template #default="scope">
          <el-button
            link
            type="primary"
            @click="openForm('update', scope.row.id)"
          >
            编辑
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <Pagination
      v-model:limit="queryParams.pageSize"
      v-model:page="queryParams.pageNo"
      :total="total"
      @pagination="getList"
    />
    <div class="clear-both"></div>
  </Dialog>
  <!-- 表单弹窗：添加/修改 -->
  <UserWithdrawForm ref="formRef" @success="getList" />
</template>
<script lang="ts" setup>
  import { dateFormatter } from '@/utils/formatTime'
  import { PackageOrderApi, PackageOrderVO } from '@/api/pay/packageorder'
  import { getBoolDictOptions, DICT_TYPE, getStrDictOptions, getIntDictOptions } from '@/utils/dict'

  import UserWithdrawForm from '@/views/member/withdraw/UserWithdrawForm.vue'
  import * as WrittenApi from '@/api/member/written'
  defineOptions({ name: 'UserOrderList' })
  const message = useMessage() // 消息弹窗
  const total = ref(0) // 列表的总页数
  const list = ref<any[]>([]) // 列表的数据
  const loading = ref(false) // 列表的加载中
  const dialogVisible = ref(false) // 弹窗的是否展示
  const queryParams = ref({
    pageNo: 1,
    pageSize: 10,
    userId: null
  }) // 查询参数
  const queryFormRef = ref() // 搜索的表单
  /** 打开弹窗 */
  const open = (ids: number[]) => {
    queryParams.value.userId = ids
    // 打开时重置查询，防止发送列表剩余数量未更新的问题
    resetQuery()

    dialogVisible.value = true
  }
  defineExpose({ open }) // 提供 open 方法，用于打开弹窗


  const formRef = ref()
  const openForm = (type: string, id?: number) => {
    formRef.value.open(type, id)
  }
  /** 查询列表 */
  const getList = async () => {
    loading.value = true
    try {
      const data = await WrittenApi.getMemberWithdrawPage(queryParams.value)
      list.value = data.list
      total.value = data.total
    } finally {
      loading.value = false
    }
  }

  /** 搜索按钮操作 */
  const handleQuery = () => {
    queryParams.value.pageNo = 1
    getList()
  }

  /** 重置按钮操作 */
  const resetQuery = () => {
    queryFormRef?.value?.resetFields()
    handleQuery()
  }
</script>
